using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace CMS.Core.Domain
{
    public class Helper
    {
        #region Create Instance
        private static Helper instance = null;
        public static Helper Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new Helper();
                }
                return instance;
            }
        }
        #endregion

        #region Days
        public DateTime GetStartOfDay(DateTime date)
        {
            return new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, 0);
        }

        public DateTime GetEndOfDay(DateTime date)
        {
            return new DateTime(date.Year, date.Month,
                                 date.Day, 23, 59, 59, 999);
        }

        public DateTime GetLastDayOfMonth(DateTime dtDate)
        {
            DateTime dtTo = dtDate;
            // overshoot the date by a month
            dtTo = dtTo.AddMonths(1);
            // remove all of the days in the next month
            // to get bumped down to the last day of the
            // previous month
            dtTo = dtTo.AddDays(-(dtTo.Day));
            // return the last day of the month
            return dtTo;
        }

        public DateTime GetLastDayOfMonth(int iMonth, int Year)
        {
            DateTime dtTo = new DateTime(Year, iMonth, 1);
            // overshoot the date by a month

            dtTo = dtTo.AddMonths(1);
            // remove all of the days in the next month
            // to get bumped down to the last day of the
            // previous month
            dtTo = dtTo.AddDays(-(dtTo.Day));
            // return the last day of the month
            return dtTo;
        }

        public List<T> ConvertToListOf<T>(IList<T> iList)
        {
            List<T> result = new List<T>();
            foreach (T value in iList)
                result.Add(value);

            return result;
        }
        #endregion
    }
}
